#include "mainwindow.h"
#include "./Forms/ui_mainwindow.h"

#include "QStackedWidget"
#include "manage_page.h"
#include "data_analysis.h"
#include "help.h"
#include "QButtonGroup"
#include <QFile>
#include <QMessageBox>
//#include "QOverload"
#include "QAbstractButton"
#include <QLabel>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    initUI();

    theme = "gray";

    QFile login_style(":/styles/mainWnd_" + theme +".css");
    login_style.open(QFile::ReadOnly);
    if (!login_style.isOpen()) {
        QMessageBox::warning(this, "","open failed!");
    }
    this->setStyleSheet(login_style.readAll());
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::initUI()
{
    manage_page* manageWnd = new manage_page;
    data_analysis* data_alyWnd = new data_analysis;
    help* helpWnd = new help;

    ui->stackedWidget->addWidget(manageWnd);
    ui->stackedWidget->addWidget(data_alyWnd);
    ui->stackedWidget->addWidget(helpWnd);

    QButtonGroup* btnGroup = new QButtonGroup;
    btnGroup->addButton(ui->manageWndBtn, 0);
    btnGroup->addButton(ui->dataAnalysisWndBtn, 1);
    btnGroup->addButton(ui->helpWnd, 2);
    connect(btnGroup, QOverload<int>::of(&QButtonGroup::idClicked), ui->stackedWidget, &QStackedWidget::setCurrentIndex);
//    QOverload<int>::of(&QButtonGroup::buttonClicked);

    // 设置默认选中的页面
    btnGroup->button(0)->setChecked(true);
    ui->stackedWidget->setCurrentIndex(0);

    initStatusBar();

}

void MainWindow::initStatusBar()
{
    auto locationLabel = new QLabel("July");
    locationLabel->setAlignment(Qt::AlignCenter);
    locationLabel->setMinimumSize(locationLabel->sizeHint());
    //QLabel *aixLabel;
    auto aixLabel = new QLabel("状态栏非永久消息");

    //Optional
//    statusBar()->setStyleSheet(QString("QStatusBar::item{border: 0px}")); // 设置不显示label的边框
//    statusBar()->setSizeGripEnabled(false); //设置是否显示右边的大小控制点
    statusBar()->addWidget(locationLabel);
    statusBar()->addWidget(aixLabel, 1);

    QLabel *per1 = new QLabel("Ready1", this);
    QLabel *per2 = new QLabel("Ready2", this);
    QLabel *per3 = new QLabel("Ready3", this);
    statusBar()->addPermanentWidget(per1); //现实永久信息
    statusBar()->addPermanentWidget(per2);
    statusBar()->insertPermanentWidget(2, per3);

    statusBar()->showMessage("Status is here...", 3000); // 显示临时信息，时间3秒钟.
}

